<!--
 * @Author: your name
 * @Date: 2021-06-24 16:58:32
 * @LastEditTime: 2021-06-26 09:59:00
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \@C@DOCUMENT\briup_hlyShixun2\protect\briup-ui\src\pages\admin\check\OrderComment.vue
-->
<template>
  <!-- 订单评论审核 -->
  <div class="Order_Review">
    <div class="Order_Review_Search">

      <el-form :inline="true" :model="searchForm" class="demo-form-inline">

        <el-form-item>
          <el-input v-model="searchForm.content" placeholder="请输入关键字" />
        </el-form-item>

        <el-form-item>
          <el-input v-model="searchForm.orderId" placeholder="请输入订单编号" />
        </el-form-item>

        <el-form-item>
          <el-select v-model="searchForm.status" clearable placeholder="请选择状态">
            <el-option label="通过" value="通过" />
            <el-option label="不通过" value="不通过" />
            <el-option label="未审核" value="未审核" />

          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="toSearch">查询</el-button>
        </el-form-item>

      </el-form>

    </div>

    <div class="Order_Review_Form">

      <el-table v-loading="loading" align="center" element-loading-spinner="el-icon-loading" :data="tableData" style="width: 100%">
        <el-table-column align="center" type="index" label="序号" width="120" />
        <el-table-column align="center" prop="content" label="评论内容" width="180" />
        <el-table-column align="center" prop="customerId" label="顾客编号" width="150" />
        <el-table-column align="center" prop="orderId" label="订单编号" width="150" />
        <el-table-column align="center" prop="commentTime" label="评论时间" width="200" :formatter="formatDate" />
        <el-table-column align="center" prop="status" label="评论状态" width="150">

          <template slot-scope="scope">
            <el-tag
              size="mini"
              :type="scope.row.status=='通过'?'success':'danger'"
            >{{ scope.row.status }}</el-tag>
          </template>

        </el-table-column>

        <el-table-column align="center" fixed="right" label="操作" width="150">
          <template slot-scope="scope">
            <!-- <a class="green_info" type="text" size="small" @click.prevent="toEdit(scope.row)">编辑</a> -->
            <a class="red_info" type="text" size="small" @click.prevent="toDelete(scope.row.id)">删除</a>
            <!-- <a class="blue_info" type="text" size="small" @click.prevent="toDetails(scope.row.id)">详情</a> -->
          </template>
        </el-table-column>

        <!-- <el-table-column prop="description" label="描述"></el-table-column> -->
      </el-table>

    </div>

    <div class="Order_Review_Page">

      <!-- <span class="demonstration">完整功能</span> -->

      <el-pagination
        :current-page="params.page"
        :page-sizes="[2,5,10,15,20,30,50,100]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />

    </div>

  </div>
</template>

<script>
import { pageQuery, deleteById } from '@/api/orderComment'
// import { deleteById } from "@/api/orderComment";

export default {
  data() {
    return {
      categoryData: [],

      searchForm: {
        type: '',
        status: '',
        userId: ''
      },

      tableData: [],

      total: 0,

      searchForm: {
        user: '',
        region: ''
      },
      params: {
        page: 1,
        pageSize: 10
      }

    }
  },
  computed: {},
  watch: {
    // 深度监听分页参数
    params: {
      handler() {
        this.queryData()
      },
      deep: true
    }
  },
  created() {
    this.queryCategoryData()
    this.queryData()
  },
  mounted() {},
  methods: {

    toDelete(id) {
      this.$confirm('此操作将永久删除这条数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async() => {
          await this.deleteById({ id })
          this.queryData()
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },

    toSearch() {
      // console.log('submit!');
      this.params.page = 1
      this.queryData()
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.params = {
        page: 1,
        pageSize: val
      }
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.params.page = val
    },

    formatDate(row, column) {
      const date = new Date(parseInt(row.commentTime))
      const Y = date.getFullYear() + '-'
      const M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) + '-' : date.getMonth() + 1 + '-'
      const D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' '
      const h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':'
      const m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':'
      const s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
      return Y + M + D + h + m + s
    },

    async queryCategoryData() {
      const res = await pageQuery({ page: 1, pageSize: 100 })
      // console.log(res.data.list);
      this.categoryData = res.data.list
    },

    async queryData() {
      this.loading = true

      for (const key in this.searchForm) {
        if (!this.searchForm[key]) {
          delete this.searchForm[key]
        }
      }
      const tempObj = { ...this.searchForm }
      // 对时间进行处理为后台需要的数据
      if (tempObj.time) {
        tempObj.beginTime = tempObj.time[0]
        tempObj.endTime = tempObj.time[1]
        delete tempObj.time
      }
      const res = await pageQuery({
        ...this.params,
        ...tempObj
      })
      this.tableData = res.data.list
      this.total = res.data.total
      this.loading = false
    }

  }
}
</script>

<style lang="scss" scoped>
  .Order_Review_Search{
    display: flex;
  }
  .demo-form-inline{
    margin-left: 15px;
  }
  .Order_Review_Page{
    float: right;
  }
</style>
